jsx3.require("jsx3.gui.Button");

/**
 * A special tab prototype object designed for use with the com.gix.gui.TabbedPane prototype object.
 */
jsx3.Class.defineClass(
        "com.gix.gui.Tab",
        jsx3.gui.Button,
        null,
        function (Tab, Tab_prototype) {

            /**
             * {jsx3.gui.Block} the content area into which the content for this tab will be loaded.  This content area
             * is NOT serialized when saving the content out to a gui xml component file.  The loading of content into this
             * content pane should be done dynamically, on-demand.
             */
            Tab_prototype.contentPane = null;

            /**
             * instance initializer
             * @param strName {String} unique name distinguishing this object from all other JSX GUI objects in the JSX application
             * @param intLeft {int} left position (in pixels) of the object relative to its parent container; not required if button is one of: jsx3.gui.Button.SYSTEMOPEN, jsx3.gui.Button.DIALOGCLOSE, jsx3.gui.Button.DIALOGALPHA, jsx3.gui.Button.DIALOGSHADE
             * @param intTop {int} top position (in pixels) of the object relative to its parent container; not required if button is one of: jsx3.gui.Button.SYSTEMOPEN, jsx3.gui.Button.DIALOGCLOSE, jsx3.gui.Button.DIALOGALPHA, jsx3.gui.Button.DIALOGSHADE
             * @param intWidth {int} width (in pixels) of the object; not required if button is one of: jsx3.gui.Button.SYSTEMOPEN, jsx3.gui.Button.DIALOGCLOSE, jsx3.gui.Button.DIALOGALPHA, jsx3.gui.Button.DIALOGSHADE
             * @param strText {String} text to display in the given button; if null JSXTABLEHEADERCELL.DEFAULTTEXT is used
             */
            Tab_prototype.init = function(strName, intLeft, intTop, intWidth, strText) {
                this.selectedImg = "background-image: url(" + tibco.admin.Main.getServer().resolveURI("jsxaddin://user!MatrixAdmin/images/matrix/tab_selected.jpg") + "); background-repeat: repeat; background-position: 0px 0px;";
                this.unselectedImg = "background-image: url(" + tibco.admin.Main.getServer().resolveURI("jsxaddin://user!MatrixAdmin/images/matrix/tab.jpg") + "); background-repeat: repeat; background-position: 0px 0px;";
                if(!strText) {
                    strText = "[tab text]";
                }
                this.jsxsuper(strName, intLeft, intTop, intWidth, strText);
                this.setHeight("20");
//                this.setBackgroundColor("#396570");
                this.setFontName(tibco.admin.Main.getServer().getDynamicProperty("@addin@Tab Font"));
                this.setFontSize(tibco.admin.Main.getServer().getDynamicProperty("@addin@Tab Font Size"));
                this.setFontWeight(tibco.admin.Main.getServer().getDynamicProperty("@addin@Tab Font Weight"));
                this.setPadding("3 10 0 10");
                this.setMargin("0 5 0 0");
                this.setBorder("solid 0px #7b797a; solid 1px #7b797a; solid 0px #7b797a; solid 1px #7b797a;");
                this.setColor(tibco.admin.Main.getServer().getDynamicProperty("@addin@Tab Font Color"), true);
                this.subscribe(jsx3.gui.Interactive.EXECUTE,this,this.select);
            };

            Tab_prototype.onSetParent = function() {
                var ret = this.jsxsuper();
                try {
                    this.selectedImg = "background-image: url(" + tibco.admin.Main.getServer().resolveURI("jsxaddin://user!MatrixAdmin/images/matrix/tab_selected.jpg") + "); background-repeat: repeat; background-position: 0px 0px;";
                    this.unselectedImg = "background-image: url(" + tibco.admin.Main.getServer().resolveURI("jsxaddin://user!MatrixAdmin/images/matrix/tab.jpg") + "); background-repeat: repeat; background-position: 0px 0px;";
                }
                catch(ex) {
                    // do nothing
                }
                this.deselect();
                return ret;
            };

            /**
             * Selects this Tab from all of the Tabs owned by the parent TabbedPane
             * Automatically handles the deselection of any previously selected Tab.
             */
            Tab_prototype.select = function() {
                this.selected = true;
//                this.setColor("#F9DB6D")
                this.setCSSOverride(this.selectedImg)
//                this.setBorder("1px solid black; 1px solid black; 1px solid white; 1px solid black;")
                this.getParent().getParent().getParent().tabSelected(this);
                this.repaint();
            };

            /**
             * Deselects the tab.  This removes the icon and other styles that indicate that the tab is selected.
             */
            Tab_prototype.deselect = function() {
                this.selected = false;
//                this.setColor("#BDE0EA");
//                this.setBorder("1px solid black; 1px solid black; 0px solid black; 1px solid black;")
                this.setCSSOverride(this.unselectedImg);
                this.repaint();
            }

            /**
             * Gets the content pane bound to this tab, for loading content into.
             *
             * @return {jsx3.gui.Block} this tab's content area, for loading content into.
             */
            Tab_prototype.getContentPane = function() {
                if(!this.contentPane) {
                    this.contentPane = new jsx3.gui.Block("blkTabContentPane", 0, 0, "100%", "100%", null);
                    this.contentPane.setDisplay(jsx3.gui.Block.DISPLAYNONE, false);
                }
                return this.contentPane;
            };
        })